<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2018/3/19
 * Time: 16:45
 */

include_once __DIR__ . '/vendor/autoload.php';

$file = 'https://item.jd.com/10058164.html';
phpQuery::newDocumentFileHTML($file);

function format($html){
    return trim(strip_tags(utf8_encode($html)));
}

$book['title'] = format(pq('h1')->html());
$book['author'] = format(pq('#p-author')->html());
$book['isbn'] = explode('：',pq('#parameter2>li')->texts()[1])[1];
$book['publish'] = format(pq('a[class="name"]')->html());
$book['category'] = format(pq('div[class="breadcrumb"]>span>a:first')->html());



$file2 = 'https://dx.3.cn/desc/10058164';
$ch = curl_init($file2);
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=curl_exec($ch);
curl_close($ch);
$content = str_replace('\n','',$content);
$content = str_replace('\\','',substr($content,42,-3));

phpQuery::newDocument($content);

$book_profile =  utf8_decode(pq('#detail-tag-id-3 div[class="book-detail-content"]')->html());
$book_category =  utf8_decode(pq('#detail-tag-id-6 div[class="book-detail-content"]')->html());
$book_author_profile =  utf8_decode(pq('#detail-tag-id-4 div[class="book-detail-content"]')->text());
